package com.springboot.interceptor;

import com.springboot.dto.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理器,处理新增的异常，对于有特殊逻辑的返回直接定义个新方法，参考ServiceException
 */
@ControllerAdvice
@Component
@ResponseBody
public class GlobalExceptionHandler {

    private final static Logger LOGGER = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(Exception.class)
    public Result<String> handlerException(Exception e){
        LOGGER.error("Oops", e);
        return new Result<>("error", "服务器错误", "", "","500");
    }
}
